-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(runner/stack-trace): solve issue #545 + test #1564
Conversation
awesome. please merge this :) 👍 thanks @rstacruz. |
@a8m That's pretty sweet! danielstjules:~/git/mocha (master =)
$ cat example.js
it('test', function(done) {
done(new Error('Something went wrong!'));
});
danielstjules:~/git/mocha (master =)
$ ./bin/mocha example.js
․
0 passing (4ms)
1 failing
1) test:
Error: Something went wrong!
at Context.<anonymous> (/Users/danielstjules/git/mocha/example.js:2:8)
at Test.Runnable.run (/Users/danielstjules/git/mocha/lib/runnable.js:233:15)
at Runner.runTest (/Users/danielstjules/git/mocha/lib/runner.js:387:10)
at /Users/danielstjules/git/mocha/lib/runner.js:470:12
at next (/Users/danielstjules/git/mocha/lib/runner.js:312:14)
at /Users/danielstjules/git/mocha/lib/runner.js:322:7
at next (/Users/danielstjules/git/mocha/lib/runner.js:257:23)
at Immediate._onImmediate (/Users/danielstjules/git/mocha/lib/runner.js:289:5)
at processImmediate [as _immediateCallback] (timers.js:358:17)
danielstjules:~/git/mocha (master =)
$ git checkout stack-trace
Switched to branch 'stack-trace'
danielstjules:~/git/mocha (stack-trace)
$ ./bin/mocha example.js
․
0 passing (7ms)
1 failing
1) test:
Error: Something went wrong!
at Context.<anonymous> (example.js:2:8)
at Test.Runnable.run (lib/runnable.js:229:15)
at Runner.runTest (lib/runner.js:390:10)
at lib/runner.js:473:12
at next (lib/runner.js:315:14)
at lib/runner.js:325:7
at next (lib/runner.js:260:23)
at Immediate._onImmediate (lib/runner.js:292:5) In addition to the work here, I wonder if there'd be interest in removing parts of the trace that propagated from mocha itself. 75% of the calls in that trace are from runner.js, which isn't something I think we need to see? For example, with the test case above, I think the following output would be a lot nicer:
You'd just have to traverse the trace, bottom up, in search of the first line that wasn't a file in mocha. Once found, just drop the lines below. This way you're not hiding any information related to the user's code. I remember doing something similar with https://github.com/danielstjules/pho a while back. |
@danielstjules you get this trace because you run it from mocha itself (it's assume that is your code, and you care of it). |
Exactly what I hoped for. :) +1
|
|
||
return []; | ||
if (nodeVersion < 0x00090B) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps semver would be a better fit here? (semver.satisfies(process.version, '>= 0.9.11')
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe, but it's not part of this PR. see: commit
(I just fixed the indentation)
If I may just chime in with API design input, perhaps Good work! |
Good point @rstacruz, |
update: renaming flag to: |
Would you be willing to run |
sure @danielstjules |
ping @danielstjules |
Sorry to nitpick, for some reason a8m@8d90e59 still contains changes to extraGlobals, along with a bunch of other (and totally valid) style changes. Would you mind force-pushing https://github.com/danielstjules/mocha/commits/stack-trace onto your branch? I cleaned up that second commit a bit (went from 400 line changes, to 270) |
PTAL @danielstjules |
LGTM :) +1 |
@travisjeffery can you please take a look ? |
i tried this and it didn't work for me. lemme try again... |
ah nvm there we go, yup lgtm |
shorten stack traces by default, add --full-trace
That's awesome, thx @travisjeffery |
Is this something that will land in 2.3.0? I'll update mocha-clean (the module this was based off of) to throw a warning for newer versions of mocha. |
@rstacruz supposedly. I'm very excited to see this published soon. 😄 |
👍
|
This is actually super UNhelpful in certain cases (mainly async things); I'm running Mocha programmatically and can't seem to work out how to disable this. Specifying |
Seems to be using |
It's set here: https://github.com/mochajs/mocha/blob/master/lib/mocha.js#L429 |
|
Indeed, something is going wrong. It doesn't do the trick. |
Can you share a Gist with sample code that reproduces the issue? |
Not easily, but it may be indirectly my fault; I'll have to dig deeper. I don't see why the 'this' argument would be wrong and mocha still run at all, but I'll find out. It seemed such an obvious disconnect, that I figured at first that whoever submitted the patch just didn't test the opposite case thoroughly and made a logic error. |
Yep, I got it sorted. It's weird to set the options and then just copy them over, seems very non-DRY. I had to monkey patch mocha.run to emit an extra event; looks like there's support in the code that will let me not have to do that anymore now. Sorry for the confusion and thanks for the prompt response. In the opposite direction of my original comment, internal node filtering doesn't catch _stream_readable.js or net.js among other things; not sure if that is intentional. I'm pretty sure that all internal modules do not have paths, so that function could probably be simplified and made more forward-compatible too. |
following #545 discussion.
I added a stack-trace filter(based on @rstacruz
mocha-clean
module), ranmake
and added tests too.If for some reason someone want to stay with full stack-trace, just run mocha with the
--full-trace
flag